﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using PixelLab.Wpf;
using DataLayer;

namespace LuanVanProject
{
    /// <summary>
    /// Interaction logic for PictureContentView.xaml
    /// </summary>
    public partial class PictureContentView : UserControl
    {
        Node parentNode;
        DetailViewContent detailView;

        public DetailViewContent DetailView
        {
            get { return detailView; }
            set { detailView = value; }
        }
        public Node ParentNode
        {
            get { return parentNode; }
            set { parentNode = value; }
        }
        public PictureContentView()
        {
            InitializeComponent();
        }
        private void Image_MouseUp(object sender, MouseButtonEventArgs e)
        {
            (this.Parent as ReorderListBox).Items.Remove(this);
            image1.Source = null;
            DetailViewContent.ImageTag imgTag = (this.Tag as DetailViewContent.ImageTag);
            (imgTag.nodeContent as ImageContent).Parent.ContentList.Remove(imgTag.nodeContent as NodeContent);
        }
        public void SetImageSource(ImageSource im)
        {
            image1.Source = im;
        }
        private void Image_MouseEnter(object sender, MouseEventArgs e)
        {
          
        }
        private void Grid_MouseEnter(object sender, MouseEventArgs e)
        {
            DoubleAnimation da = new DoubleAnimation();
            da.From=0;
            da.To = 1;
            da.Duration = new Duration(TimeSpan.FromSeconds(1));
            //MyRect.BeginAnimation(HeightProperty, da);
            DeleteIcon.BeginAnimation(OpacityProperty, da);
            moveitem.BeginAnimation(OpacityProperty, da);
            AddNodeIcon.BeginAnimation(OpacityProperty, da);
        }
        private void Grid_MouseLeave(object sender, MouseEventArgs e)
        {
            DoubleAnimation da = new DoubleAnimation();
            da.From = 1;
            da.To = 0;
            da.Duration = new Duration(TimeSpan.FromSeconds(1));
           
            DeleteIcon.BeginAnimation(OpacityProperty, da);
            moveitem.BeginAnimation(OpacityProperty, da);
            AddNodeIcon.BeginAnimation(OpacityProperty, da);
        }

        private void DeleteIcon_KeyUp(object sender, KeyEventArgs e)
        {
            MessageBox.Show("key");
            if (e.Key == Key.Delete)
            {
                (this.Parent as StackPanel).Children.Remove(this);
                image1.Source = null;
            }
        }

        private void MyGrid_MouseMove(object sender, MouseEventArgs e)
        {
        }

        private void moveitem_MouseEnter(object sender, MouseEventArgs e)
        {
            ReorderListBox.SetIsDragElement(this, true);
        }

        private void moveitem_MouseLeave(object sender, MouseEventArgs e)
        {
            ReorderListBox.SetIsDragElement(this, false);
        }

        private void AddNodeIcon_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Node node = new Node();
            node.AddContent((this.Tag as DetailViewContent.ImageTag).nodeContent);
            parentNode.AddNode(node);
            NewTreeNode newTreeNode = new NewTreeNode();
            newTreeNode.ShowDialog();
            node.Name= newTreeNode.result;
            parentNode.ContentList.Remove((this.Tag as DetailViewContent.ImageTag).nodeContent);
            App.Synchronize();
            detailView.SetContain(node);
        }


    }
}
